//
//  XJYSingleTabelView.m
//  ShopMall
//
//  Created by XJY on 17/1/20.
//  Copyright © 2017年 XinJinYing. All rights reserved.
//

#import "XJYSingleTabelView.h"
#import "XJYSingleTableViewCell.h"
#import "XJYGroupViewCell.h"

@interface XJYSingleTabelView() <UITableViewDelegate,UITableViewDataSource>

@end

@implementation XJYSingleTabelView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.bounces = NO;
    }
    return self;
}

- (void)setSingleModelArray:(NSArray *)singleModelArray
{
    _singleModelArray = singleModelArray;
    //这样可以不用再解析完数据后做刷新
    [self reloadData];
}

- (void)setGroupModelArray:(NSArray *)groupModelArray
{
    _groupModelArray = groupModelArray;
    [self reloadData];
}


#pragma mark - 代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    if (_isSingle) {
//        return self.singleModelArray.count;
//    } else {
//        return self.groupModelArray.count;
//    }
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_isSingle) {
        return 170;
    } else {
        return 200;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (_isSingle) {
        XJYSingleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"singleCell"];
        if (!cell) {
            cell = [[XJYSingleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"singleCell"];
        }
        cell.singleModel = self.singleModelArray[indexPath.row];
        return cell;
    } else {
        XJYGroupViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"groupCell"];
        if (!cell) {
            cell = [[XJYGroupViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        }
        cell.imageUrl = [self.groupModelArray[indexPath.row] ImgView];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (_isSingle) {
        if (_goodsIDBlock) {
            _goodsIDBlock([self.singleModelArray[indexPath.row] GoodsId]);
        }
    } else {
        
    }
}

@end
